# -*- coding: utf-8 -*-
# @Software :   PyCharm
# @File     :   adminx.py
# @Author   :   zhaolie
# @Contact  :   zhaolie1989@gmail.com
# @Time     :   2019/11/16 9:40 下午
# @Desc     :   None      

# here put the import lib
import xadmin
from .models import Course, CourseResource, Lesson, Video


class LessonInline:
    model = Lesson
    extra = 0


class CourseAdmin:
    list_display = ["name", "desc", "detail", "degree", "learn_times",
                    "students", "fav_nums", "image", "click_nums", "add_time"]
    search_fields = ["name", "desc", "detail", "degree", "learn_times",
                     "students", "fav_nums", "image", "click_nums"]
    list_filter = ["name", "desc", "detail", "degree", "learn_times",
                   "students", "fav_nums", "click_nums", "add_time"]
    inlines = [LessonInline]

    style_fields = {"detail": "ueditor"}

    def has_delete_permission(self, obj=None):
        return True


class LessonAdmin:
    list_display = ["course", "name", "add_time"]
    search_fields = ["course__name", "name"]
    list_filter = ["course__name", "name", "add_time"]

    def has_delete_permission(self, obj=None):
        return True


class VideoAdmin:
    list_display = ["lesson", "name", "add_time"]
    search_fields = ["lesson__name", "name"]
    list_filter = ["lesson__name", "name", "add_time"]

    def has_delete_permission(self, obj=None):
        return True


class CourseResourceAdmin:
    list_display = ["course", "name", "download", "add_time"]
    search_fields = ["course__name", "name", "download"]
    list_filter = ["course__name", "name", "add_time"]

    def has_delete_permission(self, obj=None):
        return True


xadmin.site.register(Course, CourseAdmin)
xadmin.site.register(Lesson, LessonAdmin)
xadmin.site.register(Video, VideoAdmin)
xadmin.site.register(CourseResource, CourseResourceAdmin)
